package com.droidclaimsurveyor.helper.utils;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;

public class ImageString {
	public static Bitmap toBitmap(String bitmapStr) {
		int length = bitmapStr.getBytes().length;
		if(length<=0){
			return null;
		}

		byte[] encodeByte = Base64.decode(bitmapStr, Base64.DEFAULT);
		Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0,
				encodeByte.length);
		return bitmap;
		//return BitmapFactory.decodeByteArray(bitmapStr.getBytes(), 0,length);
	}

	public static String toString(Bitmap bitmap) {
		if(bitmap==null){
			return "";
		}
//		
//		ByteArrayOutputStream os = new ByteArrayOutputStream();
//		bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100,(OutputStream) os);
//		return os.toString();

		ByteArrayOutputStream os = new ByteArrayOutputStream();
		bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100,
				(OutputStream) os);
		byte[] b = os.toByteArray();
		String temp = Base64.encodeToString(b, Base64.DEFAULT);
		return temp;
	}
}
